<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title><?php echo config('shopName');?> - 添加广告 </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="<?=ADMIN_CSS;?>/general.css" rel="stylesheet" type="text/css" />
    <link href="<?=ADMIN_CSS;?>/main.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="<?=JQ_UI;?>/datetimepicker/jquery.datetimepicker.css"/ >
    <script src="<?=JQ_UI;?>/datetimepicker/jquery.js"></script>
    <script src="<?=JQ_UI;?>/datetimepicker/jquery.datetimepicker.js"></script>
    <script src="<?=JQ_UI;?>/jquery-validation-1.15.0/dist/jquery.validate.js"></script>
    <script src="<?=ADMIN_JS;?>/validate.js"></script>
</head>
<body>
<h1>
    <span class="action-span"><a href="<?php echo url("Admin/Ad/lst") ?>">广告列表</a></span>
    <span class="action-span1"><a href="<?php echo url("Admin/Index/index") ?>"><?php echo config('shopName');?></a></span>
    <span id="search_id" class="action-span1"> - 添加广告 </span>
    <div style="clear:both"></div>
</h1>
<div class="main-div">
    <form method="post" action="<?php echo url("Admin/Ad/add") ?>" id="adForm" enctype="multipart/form-data" >
        <table cellspacing="1" cellpadding="3" width="100%">
            <input type="hidden" id="logo" size="40" name="ad_img" />
            <input type="hidden"  size="40" name="ad_size" id="ad_size"/>
            <tr>
                <td class="label">广告名称</td>
                <td>
                    <input type="text" name="ad_name" maxlength="60" size="60" value=""  />
                </td>
            </tr>
            <tr>
                <td class="label">广告显示位置</td>
                <td>
                    <select name="adpos_id" id="adpos_id">
                        <option value="">请选择</option>
                        <?php foreach ($adPosition as $k=>$v): ?>
                            <option  value="<?php echo $v['id'];?>" data-width="<?php echo $v['adpos_width'] ?>" data-height="<?php echo $v['adpos_height'] ?>"><?php echo $v['adpos_name'];?>（<?php echo $v['adpos_width'] ?>*<?php echo $v['adpos_height'] ?>px）</option>
                        <?php endforeach; ?>
                    </select>
                </td>
            </tr>
            
            <tr>
                <td class="label">广告图片</td>
                <td>
                    <img id="pre_img" src="<?=JQ_UI;?>/webuploader/image.png" style="cursor: pointer;border: 1px solid #ccc;" title="可更换"/><span style="color: red" id="test_pre_img"></span>
                </td>
            </tr>
            <tr>
                <td class="label">广告链接</td>
                <td>
                    <input type="text" name="ad_url" maxlength="60" size="60" value="" />
                </td>
            </tr>

            <tr>
                <td class="label">开始时间</td>
                <td>
                    <input type="text" class="datetime" id="start_time" name="start_time" maxlength="60" size="40" value="" />
                </td>
            </tr>
            <tr>
                <td class="label">结束时间</td>
                <td>
                    <input type="text" class="datetime" id="end_time" name="end_time" maxlength="60" size="40" value="" />
                </td>
            </tr>
            <tr>
                <td class="label">是否新窗口打开</td>
                <td>
                    <input type="radio" name="open_new" value="1"/> 是
                    <input type="radio" name="open_new" value="0"  checked="checked" /> 否
                </td>
            </tr>
            <tr>
                <td class="label">是否开启</td>
                <td>
                    <input type="radio" name="enabled" value="1"  checked="checked" /> 是
                    <input type="radio" name="enabled" value="0"  /> 否
                </td>
            </tr>
            <tr>
                <td class="label">排序（正序）</td>
                <td>
                    <input type="text" name="show_order" maxlength="8" size="10" value="50"  />
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center"><br />
                    <input type="submit" class="button" value=" 确定 " />
                    <input type="reset" class="button" value=" 重置 " />
                </td>
            </tr>

        </table>
    </form>
</div>
<?php require_once  resource_path('view/public/footer.php');?>
</body>
</html>

<!--图片上传 start-->
<iframe style="display:none;" name="ifr"></iframe>
<div id="upload" style="display: none">
    <form id="pre_form" target="ifr" method="POST" action="<?php echo url('Admin/Ad/ajaxUpload');?>" enctype="multipart/form-data">
       <input type="file" name="img" onchange="ajaxUpload();"/>
    </form>
</div>
<!--图片上传 end-->

<script>
    $(function(){
        $('.datetime').datetimepicker({
            lang:'ch', //选择中文
            format:'Y-m-d H:i:s', //格式化日期时间
//            timepicker:false, //去掉时间
//            maxDate:'+1970/01/01',  //最大日期是今天
            yearStart:2015,  //最小年份
        });
        //当点击图片的时候，让它去点击上传按钮，再触发提交表单
        $('#pre_img').click(function () {
            $("#pre_form input[name='img']").click();
        });

        //广告位大小
        $('#adpos_id').change(function () {
            if($(this).val() >0)
            {
                var width = $(this).find("option:selected").data('width');
                var height = $(this).find("option:selected").data('height');
                $('#ad_size').val(width+','+height);
            }
            else
            {
                $('#ad_size').val('');
            }
        });

//        $("#adForm").validate();

    });

    function ajaxUpload()
    {
        $('#pre_form').submit();
    }
</script>